﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using LYQ.BLL;
using LYQ.Model;
using WebManager;


namespace BaoJian.WebManager.Function.ExProduct
{   
    /// <summary>
    /// 新添修改保健产品
    /// </summary>
    public partial class NewEditProduct : System.Web.UI.Page
    {
        private string oid = null;
        /// <summary>
        /// 栏目ID
        /// </summary>
        private string ColumnID = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            // oid = HttpContext.Current.Request.QueryString["OID"];
            // ColumnID = HttpContext.Current.Request.QueryString["ColumnID"];
        }

        protected void Save_Click(object sender, EventArgs e)
        {

            string strErr = "";           
            if (this.txtName.Text == "")
            {
                strErr += "Name不能为空！\\n";
            }
          
            if (this.txtPiHao.Text == "")
            {
                strErr += "PiHao不能为空！\\n";
            }
            if (this.txtZhuYaoYuanLiao.Text == "")
            {
                strErr += "ZhuYaoYuanLiao不能为空！\\n";
            }
            if (this.txtGongXiaoJiHanLiang.Text == "")
            {
                strErr += "GongXiaoJiHanLiang不能为空！\\n";
            }
            if (this.txtBaoJianGongNeng.Text == "")
            {
                strErr += "BaoJianGongNeng不能为空！\\n";
            }
            if (this.txtShiYiRenQun.Text == "")
            {
                strErr += "ShiYiRenQun不能为空！\\n";
            }
            if (this.txtBuShiYiRenQun.Text == "")
            {
                strErr += "BuShiYiRenQun不能为空！\\n";
            }
            if (this.txtShiYongFangFaYongLiang.Text == "")
            {
                strErr += "ShiYongFangFaYongLiang不能为空！\\n";
            }
            if (this.txtGuiGe.Text == "")
            {
                strErr += "GuiGe不能为空！\\n";
            }
            if (this.txtBaoZhiQi.Text == "")
            {
                strErr += "BaoZhiQi不能为空！\\n";
            }
            if (this.txtZhuCunFangFa.Text == "")
            {
                strErr += "ZhuCunFangFa不能为空！\\n";
            }
            if (this.txtZhuYiShiXiang.Text == "")
            {
                strErr += "ZhuYiShiXiang不能为空！\\n";
            }
            if (this.txtZhiXingBiaoZhunHao.Text == "")
            {
                strErr += "ZhiXingBiaoZhunHao不能为空！\\n";
            }
            if (this.txtWeiShengXuKeZhengHao.Text == "")
            {
                strErr += "WeiShengXuKeZhengHao不能为空！\\n";
            }
            if (this.txtJingHanLiang.Text == "")
            {
                strErr += "JingHanLiang不能为空！\\n";
            }
            if (this.txtShengChanChangJia.Text == "")
            {
                strErr += "ShengChanChangJia不能为空！\\n";
            }
            if (this.txtURL.Text == "")
            {
                strErr += "URL不能为空！\\n";
            }
        
            int SID = 0;// int.Parse(this.txtSID.Text);
            string Name = this.txtName.Text;
            
            string BImg = "";// this.txtBImg.Text;
            if (Session["exchnageProduceImageB"] != null)
            {
                BImg = Session["exchnageProduceImageB"] as string;
                Session["exchnageProduceImageB"] = null;
            }
            string SImg = "";// this.txtSImg.Text;
            if (Session["exchnageProduceImageS"] != null)
            {
                SImg = Session["exchnageProduceImageS"] as string;
                Session["exchnageProduceImageS"] = null;
            }
            string PiHao = this.txtPiHao.Text;
            string ZhuYaoYuanLiao = this.txtZhuYaoYuanLiao.Text;
            string GongXiaoJiHanLiang = this.txtGongXiaoJiHanLiang.Text;
            string BaoJianGongNeng = this.txtBaoJianGongNeng.Text;
            string ShiYiRenQun = this.txtShiYiRenQun.Text;
            string BuShiYiRenQun = this.txtBuShiYiRenQun.Text;
            string ShiYongFangFaYongLiang = this.txtShiYongFangFaYongLiang.Text;
            string GuiGe = this.txtGuiGe.Text;
            string BaoZhiQi = this.txtBaoZhiQi.Text;
            string ZhuCunFangFa = this.txtZhuCunFangFa.Text;
            string ZhuYiShiXiang = this.txtZhuYiShiXiang.Text;
            string ZhiXingBiaoZhunHao = this.txtZhiXingBiaoZhunHao.Text;
            string WeiShengXuKeZhengHao = this.txtWeiShengXuKeZhengHao.Text;
            string JingHanLiang = this.txtJingHanLiang.Text;
            string ShengChanChangJia = this.txtShengChanChangJia.Text;
            string URL = this.txtURL.Text;


            LYQ.Model.Product model = new LYQ.Model.Product();
            model.SID = SID;
            model.PID = Guid.NewGuid();
            model.Name = Name;
            model.BImg = BImg;
            model.SImg = SImg;
            model.PiHao = PiHao;
            model.ZhuYaoYuanLiao = ZhuYaoYuanLiao;
            model.GongXiaoJiHanLiang = GongXiaoJiHanLiang;
            model.BaoJianGongNeng = BaoJianGongNeng;
            model.ShiYiRenQun = ShiYiRenQun;
            model.BuShiYiRenQun = BuShiYiRenQun;
            model.ShiYongFangFaYongLiang = ShiYongFangFaYongLiang;
            model.GuiGe = GuiGe;
            model.BaoZhiQi = BaoZhiQi;
            model.ZhuCunFangFa = ZhuCunFangFa;
            model.ZhuYiShiXiang = ZhuYiShiXiang;
            model.ZhiXingBiaoZhunHao = ZhiXingBiaoZhunHao;
            model.WeiShengXuKeZhengHao = WeiShengXuKeZhengHao;
            model.JingHanLiang = JingHanLiang;
            model.ShengChanChangJia = ShengChanChangJia;
            model.URL = URL;
            LYQ.BLL.Product bll = new LYQ.BLL.Product();
            bll.Add(model);

            string url = URLUtility.UrlBase + "/WebManager/Function/ExProduct/product/AllProduct.aspx";
            Page.Response.Redirect(url);
        }

 
        protected void Cancle_Click(object sender, EventArgs e)
        {
            string url = URLUtility.UrlBase + "/WebManager/Function/ExProduct/product/AllProduct.aspx";
            Page.Response.Redirect(url);
        }

        protected void Upload1_Click(object sender, EventArgs e)
        {
            String savePath = @"~\uploads\ExchangeProducts\";
            string imagePath = savePath;
            savePath = Server.MapPath(savePath);
            if (FileUpload1.HasFile)
            {

                String fileName = DateTime.Now.ToString("yyyy-MM-dd") + FileUpload1.FileName;

                savePath += fileName;
                imagePath += fileName;
                FileUpload1.SaveAs(savePath);

                UploadStatusLabel.Text = "您上传的文件被存储名字为： " + fileName;
                Session["exchnageProduceImageB"] = fileName;

                Image1.ImageUrl = imagePath;


            }
            else
            {
                // Notify the user that a file was not uploaded.
                UploadStatusLabel.Text = "文件上传失败";
            }
        }

        protected void Upload2_Click(object sender, EventArgs e)
        {
            String savePath = @"~\uploads\ExchangeProducts\";
            string imagePath = savePath;
            savePath = Server.MapPath(savePath);
            if (FileUpload2.HasFile)
            {

                String fileName = DateTime.Now.ToString("yyyy-MM-dd") + FileUpload2.FileName;
                savePath += fileName;
                imagePath += fileName;
                FileUpload2.SaveAs(savePath);

                UploadStatusLabe2.Text = "您上传的文件被存储名字为： " + fileName;
                Session["exchnageProduceImageS"] = fileName;

                Image2.ImageUrl = imagePath;


            }
            else
            {
                // Notify the user that a file was not uploaded.
                UploadStatusLabe2.Text = "文件上传失败";
            }
        }
    }
}
